package com.bp.hearthealth.pulse.lnapps.bp_view

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/**
 * @author isnoam
 * @package_name SpacingItemDecoration
 */
class BPTrackSpacingItemDecoration(
    private val bottomSpacing: Int, private val marginTop: Int, vararg val marginFirstTop: Int
) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State
    ) {
        val position = parent.getChildAdapterPosition(view)
        val totalItemCount = parent.adapter?.itemCount ?: 0
        if (marginFirstTop.isNotEmpty()) {
            if (position == 0 || position == 1) {
                outRect.top = marginFirstTop[0]
            }
        }
        if (totalItemCount != 1 && totalItemCount - 1 == position) {
            outRect.bottom = bottomSpacing
        }
    }
}
